// 引入动态路由配置
import { constantRoutes, asyncRoutes } from '@/router/index'
const state = {
  routes: []
}
const mutations = {
  setRoutes(state, data) {
    state.routes = [...constantRoutes, ...data]
  }
}
const actions = {
  // 过滤路由模块
  filterRoutes(store, data) {
    console.log(asyncRoutes)
    console.log(data)
    // 过滤出授权了的动态路由对象
    const routes = asyncRoutes.filter(item => data.indexOf(item.name) !== -1)
    console.log(routes)

    // 设置动态路由对象保存起来 用于显示左边导航栏
    store.commit('setRoutes', routes)

    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}

